package javax.xianfeng.drools.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * @since 2020/04/09 22:24:46
 */
@Slf4j
public final class DrlUtils {

	private DrlUtils() {
		super();
	}

	/**
	 * 读取drl文件内容，也可从db读取
	 * 
	 * @param drlFile
	 * @return
	 * @since 2020/04/09 21:47:34
	 */
	public static String readDrlFile(String drlFile) {
		log.debug("读取drl文件: {}", drlFile);
		InputStream inputStream = DroolsUtils.class.getClassLoader().getResourceAsStream(drlFile);
		try {
			return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
		} catch (IOException e) {
			throw new RuntimeException("Drools规则文件读取异常", e);
		}
	}
}
